#include <stdio.h>
#include <stdlib.h>
#include <sys/vfs.h>
#include <error.h>

#define Gsize (1024.00*1024.00*1024.00)
#define Msize (1024.00*1024.00)

#ifndef EXT2_SUPER_MAGIC
#define EXT2_SUPER_MAGIC 0xef53
#endif

#define ARM_EXT3_SUPER_MAGIC	0x72b6

int main()
{
	long long blocks,bfree;
	struct statfs fs;

	if(statfs("/home/share/xiaozhi",&fs)<0)
	{
		perror("statfs");
		exit(0);
	}

	printf("type = %x\n",fs.f_type);      /* type of filesystem (see below) */
	printf("bsize = %ld\n",fs.f_bsize);    /* optimal (最佳的) transfer block size */
	printf("block = %ld\n",fs.f_blocks);   /* total data blocks in file system */
	printf("bfree = %ld\n",fs.f_bfree);    /* free blocks in fs */
	printf("bavail = %ld\n",fs.f_bavail);   /* free blocks avail to non-superuser */
	printf("files = %ld\n",fs.f_files);    /* total file nodes in file system */
	printf("ffree = %ld\n",fs.f_ffree);    /* free file nodes in fs */
	printf("fsid = %lld\n",fs.f_fsid);     /* file system id */
	printf("namelen = %ld\n",fs.f_namelen);  /* maximum length of filenames */

	blocks = fs.f_blocks;
	bfree = fs.f_bfree;

	printf(" blocks = %lld\n",blocks);

	if(fs.f_type==EXT2_SUPER_MAGIC)
	{
		printf("Total size of / is %f G\n",blocks*fs.f_bsize/Gsize);
		printf("Free size of / is %f G\n",bfree*fs.f_bsize/Gsize);
	}

	// for ARM
	if(fs.f_type==ARM_EXT3_SUPER_MAGIC)
	{
		printf("Total size of / is %2.1fM\n",blocks*fs.f_bsize/Msize);
		printf("Free size of / is %2.1fM\n",bfree*fs.f_bsize/Msize);
	}
}




